<?php

/**
 * managecampaigns.php
 * @package adServer
 * @filesource
 */

/*	Close the backdoor	*/
$curPage = strtoupper($_SERVER['PHP_SELF']);
if (isset($curPage) && strpos($curPage, 'INDEX.PHP') === false)
    header('Location:./index.php');

require_once (CLASS_PATH . 'template.class.php');
/* Load the side menu */
$sideMenu = file_get_contents(TEMPLATE_PATH . 'sideMenu.tpl');

/*	load the page header	*/
$header = new template(TEMPLATE_PATH . 'header.tpl');
$header->replace('&&SIDEMENU&&', $sideMenu);
$header->replace('&&STYLE&&', $session->loggedIn ? "style='display:block;'" : "");
$header->replace('&&USER&&', $session->username);

/*	Load the page content	*/
$pageContent = new template(TEMPLATE_PATH . $nextAction . '.tpl');


/*	Retrieve the campaigns from DB	*/
$results = $session->dbHandle->get_results(SQL_GET_CAMPAIGNS);

$optionsHtml = '';
foreach ($results as $result) {
    $optionsHtml .= '<option>' . $result['campaign'] . '</option>';
}


$pageContent->replace('&&CAMPAIGN&&', $optionsHtml);
$pageContent->replace('&&ERRMSG&&', urldecode($_GET['msg']));

/*	Echo the page	*/
echo $header->templateHtml;
echo $pageContent->templateHtml;

?>